// [455]-分发饼干
struct Solution;

//leetcode submit region begin(Prohibit modification and deletion)
impl Solution {
    pub fn find_content_children2(g: Vec<i32>, s: Vec<i32>) -> i32 {
        if s.len() <= 0 {
            return 0;
        }
        let mut g = g;
        let mut s = s;
        g.sort();
        s.sort();
        let mut s_index = 0;
        let mut ans = 0;
        for num in g {
            for j in s_index..s.len() {
                if s[j] >= num {
                    ans += 1;
                    s_index = j + 1;
                    break;
                };
            }
            if s_index >= s.len() {
                break;
            }
        }
        ans
    }

    pub fn find_content_children(g: Vec<i32>, s: Vec<i32>) -> i32 {
        let mut g = g;
        let mut s = s;
        let mut ans = 0;
        g.sort();
        s.sort();
        for &x in &s {
            if ans < g.len() && g[ans] <= x {
                ans += 1;
            }
        }
        ans as _
    }

}
//leetcode submit region end(Prohibit modification and deletion)

/// 总结：看清楚条件，最好哪行代码对应哪个条件标识出来

#[test]
fn main() {
    let a = vec![1, 2, 3];
    let s = vec![1, 1];
    assert_eq!(Solution::find_content_children(a, s), 1);
    let a = vec![1, 2];
    let s = vec![1, 2, 3];
    assert_eq!(Solution::find_content_children(a, s), 2);
}
